package a.b.controller;

import a.b.controller.utils.R;
import a.b.pojo.Book;
import a.b.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private IBookService bookService;

    //分页信息
    @GetMapping("/{yemashu}/{tiaoshu}")
    public R getPage(@PathVariable("yemashu") Integer yemashu, @PathVariable("tiaoshu") Integer tiaoshu){
        return new R(true,bookService.getPage(yemashu,tiaoshu));
    }

    @GetMapping("{id}")
    public R getById(@PathVariable("id") Integer id){
        return new R(true,bookService.getById(id));
    }

    //所有数据
    @GetMapping
    public R getAll(){
        return new R(true,bookService.list());
    }

    //添加
    @PostMapping
    public R save(@RequestBody Book book){
        return new R(bookService.save(book));
    }

    //修改
    @PutMapping
    public R update(@RequestBody Book book){
        return new R(bookService.updateById(book));
    }

    //删除
    @DeleteMapping("{id}")
    public R delete(@PathVariable("id") Integer id){
        return new R(bookService.removeById(id));
    }


}
